function hashChunk(chunk, hasher) {
    return new Promise((resolve, reject) => {
        const fileReader = new FileReader();
        fileReader.onload = async (e) => {
            const view = new Uint8Array(e.target.result);
            hasher.update(view);
            resolve();
        };
        fileReader.readAsArrayBuffer(chunk);
    });
}

const getFileMd5 = async (file, chunkSize, cb) => {
    let hasher = await hashwasm.createMD5();
    hasher.init();
    const chunkNumber = Math.floor(file.size / chunkSize);

    for (let i = 0; i <= chunkNumber; i++) {
        const chunk = file.slice(
            chunkSize * i,
            Math.min(chunkSize * (i + 1), file.size)
        );
        await hashChunk(chunk, hasher);
        cb((i * 100) / chunkNumber);
    }
    const hash = hasher.digest();
    return Promise.resolve(hash);
};
